< previous page page_709 next page >

Page 709
Retrieving Data with the Request Object
The Request object allows ASP code to access everything about an incoming browser request. You already know that you can use the Request object to get the value of a parameter in an URL by using the parameter name with the QueryString property. Like many other collections, QueryString has a Count property and an index which allow you to iterate through the values:
Dim n
For n = 1 to Request.QueryString.Count
   Response.Write ("Parameter " & n & "Value = " & Request.QueryString(n) &
"<BR>")
Next
You can also receive information from HTML forms with the Form collection of the Request object. For example, if you have a form field name txtLastName, you can display the value submitted with the following code:
Response.Write "You entered " & Request.Form("txtLastName")
As you can see, a lot of the information in the Request object is accessed through collections. You can use a ForEach loop to list all of the objects in a collection. Listing 31.7 displays all of the information in the Request.Servervariables collection.
Listing 31.7 ASPDEMO.ZIPVARIABLES.ASP Lists the Contents of the ServerVariables Collection
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD><TITLE>Variables</TITLE></HEAD>
<BODY>
<HR>
<H1 align="center">Server Variables</H1>
<%
For Each item in Request.ServerVariables
%>
<STRONG><%=item%></STRONG>=<%=Request.ServerVariables(item)%><BR>
<%
Next
%>
</BODY>
</HTML>
Create a new ASP file on your Web server, VARIABLES.ASP. Enter the code from Listing 31.7 and load the page in your browser. You should see a list of all the server variables, as shown in Figure 31.6.
note.gif You could add more For . . . Each loops to Listing 31.2 to show what is contained in other collections, such as the Request.Form collection, and use it as a debugging tool. square.gif

 
< previous page page_709 next page >